package com.zzw.zim.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzw.zim.common.utils.Result;
import com.zzw.zim.system.dto.AddSysRoleDTO;
import com.zzw.zim.system.dto.EditSysRoleDTO;
import com.zzw.zim.system.dto.QueryRolePageDTO;
import com.zzw.zim.system.service.SysRoleService;
import com.zzw.zim.system.vo.SysRoleVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


/**
 * 角色管理
 *
 * @author XiaoJie
 * @date 2025-09-01 09:43:18
 */
@Tag(name = "系统角色管理控制器")
@RestController
@RequestMapping("system/role")
public class SysRoleController {
    @Resource
    private SysRoleService roleService;

    @PostMapping("add")
    @Operation(summary = "新增角色")
    public Result<String> addRole (@RequestBody AddSysRoleDTO dto) {
        return Result.ok(roleService.savaRole(dto));
    }

    @PostMapping("remove/{id}")
    @Operation(summary = "删除角色")
    public Result<String> removeRole (@PathVariable("id") String id) {
        return Result.ok(roleService.removeById(id)?"删除成功":"删除失败");
    }

    @PostMapping("edit")
    @Operation(summary = "编辑角色")
    public Result<String> editRole (@RequestBody EditSysRoleDTO dto) {
        return Result.ok(roleService.editRole(dto));
    }

    @PostMapping("query")
    @Operation(summary = "角色分页查询")
    public Result<Page<SysRoleVo>> queryRolePage (@RequestBody QueryRolePageDTO dto) {
        return Result.ok(roleService.queryRolePage(dto));
    }

    @PostMapping("queryInfo/{id}")
    @Operation(summary = "查询角色详情")
    public Result<SysRoleVo> queryInfo (@PathVariable("id") String id) {
        return Result.ok(roleService.queryInfo(id));
    }

}
